home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / lib / python2.6 / distutils / command / install.py < prev    next >
Encoding:
Python Source  |  2009-04-18  |  27.5 KB  |  718 lines

  1. """distutils.command.install
  2.  
  3. Implements the Distutils 'install' command."""
  4.  
  5. from distutils import log
  6.  
  7. # This module should be kept compatible with Python 2.1.
  8.  
  9. __revision__ = "$Id: install.py 62788 2008-05-06 22:41:46Z christian.heimes $"
  10.  
  11. import sys, os, string
  12. from types import *
  13. from distutils.core import Command
  14. from distutils.debug import DEBUG
  15. from distutils.sysconfig import get_config_vars
  16. from distutils.errors import DistutilsPlatformError
  17. from distutils.file_util import write_file
  18. from distutils.util import convert_path, subst_vars, change_root
  19. from distutils.util import get_platform
  20. from distutils.errors import DistutilsOptionError
  21. from site import USER_BASE
  22. from site import USER_SITE
  23.  
  24.  
  25. if sys.version < "2.2":
  26.     WINDOWS_SCHEME = {
  27.         'purelib': '$base',
  28.         'platlib': '$base',
  29.         'headers': '$base/Include/$dist_name',
  30.         'scripts': '$base/Scripts',
  31.         'data'   : '$base',
  32.     }
  33. else:
  34.     WINDOWS_SCHEME = {
  35.         'purelib': '$base/Lib/site-packages',
  36.         'platlib': '$base/Lib/site-packages',
  37.         'headers': '$base/Include/$dist_name',
  38.         'scripts': '$base/Scripts',
  39.         'data'   : '$base',
  40.     }
  41.  
  42. INSTALL_SCHEMES = {
  43.     'unix_prefix': {
  44.         'purelib': '$base/lib/python$py_version_short/site-packages',
  45.         'platlib': '$platbase/lib/python$py_version_short/site-packages',
  46.         'headers': '$base/include/python$py_version_short/$dist_name',
  47.         'scripts': '$base/bin',
  48.         'data'   : '$base',
  49.         },
  50.     'unix_local': {
  51.         'purelib': '$base/local/lib/python$py_version_short/dist-packages',
  52.         'platlib': '$platbase/local/lib/python$py_version_short/dist-packages',
  53.         'headers': '$base/local/include/python$py_version_short/$dist_name',
  54.         'scripts': '$base/local/bin',
  55.         'data'   : '$base/local',
  56.         },
  57.     'deb_system': {
  58.         'purelib': '$base/lib/python$py_version_short/dist-packages',
  59.         'platlib': '$platbase/lib/python$py_version_short/dist-packages',
  60.         'headers': '$base/include/python$py_version_short/$dist_name',
  61.         'scripts': '$base/bin',
  62.         'data'   : '$base',
  63.         },
  64.     'unix_home': {
  65.         'purelib': '$base/lib/python',
  66.         'platlib': '$base/lib/python',
  67.         'headers': '$base/include/python/$dist_name',
  68.         'scripts': '$base/bin',
  69.         'data'   : '$base',
  70.         },
  71.     'unix_user': {
  72.         'purelib': '$usersite',
  73.         'platlib': '$usersite',
  74.         'headers': '$userbase/include/python$py_version_short/$dist_name',
  75.         'scripts': '$userbase/bin',
  76.         'data'   : '$userbase',
  77.         },
  78.     'nt': WINDOWS_SCHEME,
  79.     'nt_user': {
  80.         'purelib': '$usersite',
  81.         'platlib': '$usersite',
  82.         'headers': '$userbase/Python$py_version_nodot/Include/$dist_name',
  83.         'scripts': '$userbase/Scripts',
  84.         'data'   : '$userbase',
  85.         },
  86.     'mac': {
  87.         'purelib': '$base/Lib/site-packages',
  88.         'platlib': '$base/Lib/site-packages',
  89.         'headers': '$base/Include/$dist_name',
  90.         'scripts': '$base/Scripts',
  91.         'data'   : '$base',
  92.         },
  93.     'mac_user': {
  94.         'purelib': '$usersite',
  95.         'platlib': '$usersite',
  96.         'headers': '$userbase/$py_version_short/include/$dist_name',
  97.         'scripts': '$userbase/bin',
  98.         'data'   : '$userbase',
  99.         },
  100.     'os2': {
  101.         'purelib': '$base/Lib/site-packages',
  102.         'platlib': '$base/Lib/site-packages',
  103.         'headers': '$base/Include/$dist_name',
  104.         'scripts': '$base/Scripts',
  105.         'data'   : '$base',
  106.         },
  107.     'os2_home': {
  108.         'purelib': '$usersite',
  109.         'platlib': '$usersite',
  110.         'headers': '$userbase/include/python$py_version_short/$dist_name',
  111.         'scripts': '$userbase/bin',
  112.         'data'   : '$userbase',
  113.         },
  114.     }
  115.  
  116. # The keys to an installation scheme; if any new types of files are to be
  117. # installed, be sure to add an entry to every installation scheme above,
  118. # and to SCHEME_KEYS here.
  119. SCHEME_KEYS = ('purelib', 'platlib', 'headers', 'scripts', 'data')
  120.  
  121.  
  122. class install (Command):
  123.  
  124.     description = "install everything from build directory"
  125.  
  126.     user_options = [
  127.         # Select installation scheme and set base director(y|ies)
  128.         ('prefix=', None,
  129.          "installation prefix"),
  130.         ('exec-prefix=', None,
  131.          "(Unix only) prefix for platform-specific files"),
  132.         ('home=', None,
  133.          "(Unix only) home directory to install under"),
  134.         ('user', None,
  135.          "install in user site-package '%s'" % USER_SITE),
  136.  
  137.         # Or, just set the base director(y|ies)
  138.         ('install-base=', None,
  139.          "base installation directory (instead of --prefix or --home)"),
  140.         ('install-platbase=', None,
  141.          "base installation directory for platform-specific files " +
  142.          "(instead of --exec-prefix or --home)"),
  143.         ('root=', None,
  144.          "install everything relative to this alternate root directory"),
  145.  
  146.         # Or, explicitly set the installation scheme
  147.         ('install-purelib=', None,
  148.          "installation directory for pure Python module distributions"),
  149.         ('install-platlib=', None,
  150.          "installation directory for non-pure module distributions"),
  151.         ('install-lib=', None,
  152.          "installation directory for all module distributions " +
  153.          "(overrides --install-purelib and --install-platlib)"),
  154.  
  155.         ('install-headers=', None,
  156.          "installation directory for C/C++ headers"),
  157.         ('install-scripts=', None,
  158.          "installation directory for Python scripts"),
  159.         ('install-data=', None,
  160.          "installation directory for data files"),
  161.  
  162.         # Byte-compilation options -- see install_lib.py for details, as
  163.         # these are duplicated from there (but only install_lib does
  164.         # anything with them).
  165.         ('compile', 'c', "compile .py to .pyc [default]"),
  166.         ('no-compile', None, "don't compile .py files"),
  167.         ('optimize=', 'O',
  168.          "also compile with optimization: -O1 for \"python -O\", "
  169.          "-O2 for \"python -OO\", and -O0 to disable [default: -O0]"),
  170.  
  171.         # Miscellaneous control options
  172.         ('force', 'f',
  173.          "force installation (overwrite any existing files)"),
  174.         ('skip-build', None,
  175.          "skip rebuilding everything (for testing/debugging)"),
  176.  
  177.         # Where to install documentation (eventually!)
  178.         #('doc-format=', None, "format of documentation to generate"),
  179.         #('install-man=', None, "directory for Unix man pages"),
  180.         #('install-html=', None, "directory for HTML documentation"),
  181.         #('install-info=', None, "directory for GNU info files"),
  182.  
  183.         ('record=', None,
  184.          "filename in which to record list of installed files"),
  185.  
  186.         ('install-layout=', None,
  187.          "installation layout to choose (known values: deb)"),
  188.         ]
  189.  
  190.     boolean_options = ['compile', 'force', 'skip-build', 'user']
  191.     negative_opt = {'no-compile' : 'compile'}
  192.  
  193.  
  194.     def initialize_options (self):
  195.  
  196.         # High-level options: these select both an installation base
  197.         # and scheme.
  198.         self.prefix = None
  199.         self.exec_prefix = None
  200.         self.home = None
  201.         self.user = 0
  202.         self.prefix_option = None
  203.  
  204.         # These select only the installation base; it's up to the user to
  205.         # specify the installation scheme (currently, that means supplying
  206.         # the --install-{platlib,purelib,scripts,data} options).
  207.         self.install_base = None
  208.         self.install_platbase = None
  209.         self.root = None
  210.  
  211.         # These options are the actual installation directories; if not
  212.         # supplied by the user, they are filled in using the installation
  213.         # scheme implied by prefix/exec-prefix/home and the contents of
  214.         # that installation scheme.
  215.         self.install_purelib = None     # for pure module distributions
  216.         self.install_platlib = None     # non-pure (dists w/ extensions)
  217.         self.install_headers = None     # for C/C++ headers
  218.         self.install_lib = None         # set to either purelib or platlib
  219.         self.install_scripts = None
  220.         self.install_data = None
  221.         self.install_userbase = USER_BASE
  222.         self.install_usersite = USER_SITE
  223.  
  224.         # enable custom installation, known values: deb
  225.         self.install_layout = None
  226.         
  227.         self.compile = None
  228.         self.optimize = None
  229.  
  230.         # These two are for putting non-packagized distributions into their
  231.         # own directory and creating a .pth file if it makes sense.
  232.         # 'extra_path' comes from the setup file; 'install_path_file' can
  233.         # be turned off if it makes no sense to install a .pth file.  (But
  234.         # better to install it uselessly than to guess wrong and not
  235.         # install it when it's necessary and would be used!)  Currently,
  236.         # 'install_path_file' is always true unless some outsider meddles
  237.         # with it.
  238.         self.extra_path = None
  239.         self.install_path_file = 1
  240.  
  241.         # 'force' forces installation, even if target files are not
  242.         # out-of-date.  'skip_build' skips running the "build" command,
  243.         # handy if you know it's not necessary.  'warn_dir' (which is *not*
  244.         # a user option, it's just there so the bdist_* commands can turn
  245.         # it off) determines whether we warn about installing to a
  246.         # directory not in sys.path.
  247.         self.force = 0
  248.         self.skip_build = 0
  249.         self.warn_dir = 1
  250.  
  251.         # These are only here as a conduit from the 'build' command to the
  252.         # 'install_*' commands that do the real work.  ('build_base' isn't
  253.         # actually used anywhere, but it might be useful in future.)  They
  254.         # are not user options, because if the user told the install
  255.         # command where the build directory is, that wouldn't affect the
  256.         # build command.
  257.         self.build_base = None
  258.         self.build_lib = None
  259.  
  260.         # Not defined yet because we don't know anything about
  261.         # documentation yet.
  262.         #self.install_man = None
  263.         #self.install_html = None
  264.         #self.install_info = None
  265.  
  266.         self.record = None
  267.  
  268.  
  269.     # -- Option finalizing methods -------------------------------------
  270.     # (This is rather more involved than for most commands,
  271.     # because this is where the policy for installing third-
  272.     # party Python modules on various platforms given a wide
  273.     # array of user input is decided.  Yes, it's quite complex!)
  274.  
  275.     def finalize_options (self):
  276.  
  277.         # This method (and its pliant slaves, like 'finalize_unix()',
  278.         # 'finalize_other()', and 'select_scheme()') is where the default
  279.         # installation directories for modules, extension modules, and
  280.         # anything else we care to install from a Python module
  281.         # distribution.  Thus, this code makes a pretty important policy
  282.         # statement about how third-party stuff is added to a Python
  283.         # installation!  Note that the actual work of installation is done
  284.         # by the relatively simple 'install_*' commands; they just take
  285.         # their orders from the installation directory options determined
  286.         # here.
  287.  
  288.         # Check for errors/inconsistencies in the options; first, stuff
  289.         # that's wrong on any platform.
  290.  
  291.         if ((self.prefix or self.exec_prefix or self.home) and
  292.             (self.install_base or self.install_platbase)):
  293.             raise DistutilsOptionError, \
  294.                   ("must supply either prefix/exec-prefix/home or " +
  295.                    "install-base/install-platbase -- not both")
  296.  
  297.         if self.home and (self.prefix or self.exec_prefix):
  298.             raise DistutilsOptionError, \
  299.                   "must supply either home or prefix/exec-prefix -- not both"
  300.  
  301.         if self.user and (self.prefix or self.exec_prefix or self.home or
  302.                 self.install_base or self.install_platbase):
  303.             raise DistutilsOptionError("can't combine user with with prefix/"
  304.                                        "exec_prefix/home or install_(plat)base")
  305.  
  306.         # Next, stuff that's wrong (or dubious) only on certain platforms.
  307.         if os.name != "posix":
  308.             if self.exec_prefix:
  309.                 self.warn("exec-prefix option ignored on this platform")
  310.                 self.exec_prefix = None
  311.  
  312.         # Now the interesting logic -- so interesting that we farm it out
  313.         # to other methods.  The goal of these methods is to set the final
  314.         # values for the install_{lib,scripts,data,...}  options, using as
  315.         # input a heady brew of prefix, exec_prefix, home, install_base,
  316.         # install_platbase, user-supplied versions of
  317.         # install_{purelib,platlib,lib,scripts,data,...}, and the
  318.         # INSTALL_SCHEME dictionary above.  Phew!
  319.  
  320.         self.dump_dirs("pre-finalize_{unix,other}")
  321.  
  322.         if os.name == 'posix':
  323.             self.finalize_unix()
  324.         else:
  325.             self.finalize_other()
  326.  
  327.         self.dump_dirs("post-finalize_{unix,other}()")
  328.  
  329.         # Expand configuration variables, tilde, etc. in self.install_base
  330.         # and self.install_platbase -- that way, we can use $base or
  331.         # $platbase in the other installation directories and not worry
  332.         # about needing recursive variable expansion (shudder).
  333.  
  334.         py_version = (string.split(sys.version))[0]
  335.         (prefix, exec_prefix) = get_config_vars('prefix', 'exec_prefix')
  336.         self.config_vars = {'dist_name': self.distribution.get_name(),
  337.                             'dist_version': self.distribution.get_version(),
  338.                             'dist_fullname': self.distribution.get_fullname(),
  339.                             'py_version': py_version,
  340.                             'py_version_short': py_version[0:3],
  341.                             'py_version_nodot': py_version[0] + py_version[2],
  342.                             'sys_prefix': prefix,
  343.                             'prefix': prefix,
  344.                             'sys_exec_prefix': exec_prefix,
  345.                             'exec_prefix': exec_prefix,
  346.                             'userbase': self.install_userbase,
  347.                             'usersite': self.install_usersite,
  348.                            }
  349.         self.expand_basedirs()
  350.  
  351.         self.dump_dirs("post-expand_basedirs()")
  352.  
  353.         # Now define config vars for the base directories so we can expand
  354.         # everything else.
  355.         self.config_vars['base'] = self.install_base
  356.         self.config_vars['platbase'] = self.install_platbase
  357.  
  358.         if DEBUG:
  359.             from pprint import pprint
  360.             print "config vars:"
  361.             pprint(self.config_vars)
  362.  
  363.         # Expand "~" and configuration variables in the installation
  364.         # directories.
  365.         self.expand_dirs()
  366.  
  367.         self.dump_dirs("post-expand_dirs()")
  368.  
  369.         # Create directories in the home dir:
  370.         if self.user:
  371.             self.create_home_path()
  372.  
  373.         # Pick the actual directory to install all modules to: either
  374.         # install_purelib or install_platlib, depending on whether this
  375.         # module distribution is pure or not.  Of course, if the user
  376.         # already specified install_lib, use their selection.
  377.         if self.install_lib is None:
  378.             if self.distribution.ext_modules: # has extensions: non-pure
  379.                 self.install_lib = self.install_platlib
  380.             else:
  381.                 self.install_lib = self.install_purelib
  382.  
  383.  
  384.         # Convert directories from Unix /-separated syntax to the local
  385.         # convention.
  386.         self.convert_paths('lib', 'purelib', 'platlib',
  387.                            'scripts', 'data', 'headers',
  388.                            'userbase', 'usersite')
  389.  
  390.         # Well, we're not actually fully completely finalized yet: we still
  391.         # have to deal with 'extra_path', which is the hack for allowing
  392.         # non-packagized module distributions (hello, Numerical Python!) to
  393.         # get their own directories.
  394.         self.handle_extra_path()
  395.         self.install_libbase = self.install_lib # needed for .pth file
  396.         self.install_lib = os.path.join(self.install_lib, self.extra_dirs)
  397.  
  398.         # If a new root directory was supplied, make all the installation
  399.         # dirs relative to it.
  400.         if self.root is not None:
  401.             self.change_roots('libbase', 'lib', 'purelib', 'platlib',
  402.                               'scripts', 'data', 'headers')
  403.  
  404.         self.dump_dirs("after prepending root")
  405.  
  406.         # Find out the build directories, ie. where to install from.
  407.         self.set_undefined_options('build',
  408.                                    ('build_base', 'build_base'),
  409.                                    ('build_lib', 'build_lib'))
  410.  
  411.         # Punt on doc directories for now -- after all, we're punting on
  412.         # documentation completely!
  413.  
  414.     # finalize_options ()
  415.  
  416.  
  417.     def dump_dirs (self, msg):
  418.         if DEBUG:
  419.             from distutils.fancy_getopt import longopt_xlate
  420.             print msg + ":"
  421.             for opt in self.user_options:
  422.                 opt_name = opt[0]
  423.                 if opt_name[-1] == "=":
  424.                     opt_name = opt_name[0:-1]
  425.                 if opt_name in self.negative_opt:
  426.                     opt_name = string.translate(self.negative_opt[opt_name],
  427.                                                 longopt_xlate)
  428.                     val = not getattr(self, opt_name)
  429.                 else:
  430.                     opt_name = string.translate(opt_name, longopt_xlate)
  431.                     val = getattr(self, opt_name)
  432.                 print "  %s: %s" % (opt_name, val)
  433.  
  434.  
  435.     def finalize_unix (self):
  436.  
  437.         if self.install_base is not None or self.install_platbase is not None:
  438.             if ((self.install_lib is None and
  439.                  self.install_purelib is None and
  440.                  self.install_platlib is None) or
  441.                 self.install_headers is None or
  442.                 self.install_scripts is None or
  443.                 self.install_data is None):
  444.                 raise DistutilsOptionError, \
  445.                       ("install-base or install-platbase supplied, but "
  446.                       "installation scheme is incomplete")
  447.             return
  448.  
  449.         if self.user:
  450.             if self.install_userbase is None:
  451.                 raise DistutilsPlatformError(
  452.                     "User base directory is not specified")
  453.             self.install_base = self.install_platbase = self.install_userbase
  454.             self.select_scheme("unix_user")
  455.         elif self.home is not None:
  456.             self.install_base = self.install_platbase = self.home
  457.             self.select_scheme("unix_home")
  458.         else:
  459.             self.prefix_option = self.prefix
  460.             if self.prefix is None:
  461.                 if self.exec_prefix is not None:
  462.                     raise DistutilsOptionError, \
  463.                           "must not supply exec-prefix without prefix"
  464.  
  465.                 self.prefix = os.path.normpath(sys.prefix)
  466.                 self.exec_prefix = os.path.normpath(sys.exec_prefix)
  467.  
  468.             else:
  469.                 if self.exec_prefix is None:
  470.                     self.exec_prefix = self.prefix
  471.  
  472.             self.install_base = self.prefix
  473.             self.install_platbase = self.exec_prefix
  474.             if self.install_layout:
  475.                 if self.install_layout.lower() in ['deb']:
  476.                     self.select_scheme("deb_system")
  477.                 else:
  478.                     raise DistutilsOptionError(
  479.                         "unknown value for --install-layout")
  480.             elif self.prefix_option or 'real_prefix' in sys.__dict__:
  481.                 self.select_scheme("unix_prefix")
  482.             else:
  483.                 self.select_scheme("unix_local")
  484.  
  485.     # finalize_unix ()
  486.  
  487.  
  488.     def finalize_other (self):          # Windows and Mac OS for now
  489.  
  490.         if self.user:
  491.             if self.install_userbase is None:
  492.                 raise DistutilsPlatformError(
  493.                     "User base directory is not specified")
  494.             self.install_base = self.install_platbase = self.install_userbase
  495.             self.select_scheme(os.name + "_user")
  496.         elif self.home is not None:
  497.             self.install_base = self.install_platbase = self.home
  498.             self.select_scheme("unix_home")
  499.         else:
  500.             if self.prefix is None:
  501.                 self.prefix = os.path.normpath(sys.prefix)
  502.  
  503.             self.install_base = self.install_platbase = self.prefix
  504.             try:
  505.                 self.select_scheme(os.name)
  506.             except KeyError:
  507.                 raise DistutilsPlatformError, \
  508.                       "I don't know how to install stuff on '%s'" % os.name
  509.  
  510.     # finalize_other ()
  511.  
  512.  
  513.     def select_scheme (self, name):
  514.         # it's the caller's problem if they supply a bad name!
  515.         scheme = INSTALL_SCHEMES[name]
  516.         for key in SCHEME_KEYS:
  517.             attrname = 'install_' + key
  518.             if getattr(self, attrname) is None:
  519.                 setattr(self, attrname, scheme[key])
  520.  
  521.  
  522.     def _expand_attrs (self, attrs):
  523.         for attr in attrs:
  524.             val = getattr(self, attr)
  525.             if val is not None:
  526.                 if os.name == 'posix' or os.name == 'nt':
  527.                     val = os.path.expanduser(val)
  528.                 val = subst_vars(val, self.config_vars)
  529.                 setattr(self, attr, val)
  530.  
  531.  
  532.     def expand_basedirs (self):
  533.         self._expand_attrs(['install_base',
  534.                             'install_platbase',
  535.                             'root'])
  536.  
  537.     def expand_dirs (self):
  538.         self._expand_attrs(['install_purelib',
  539.                             'install_platlib',
  540.                             'install_lib',
  541.                             'install_headers',
  542.                             'install_scripts',
  543.                             'install_data',])
  544.  
  545.  
  546.     def convert_paths (self, *names):
  547.         for name in names:
  548.             attr = "install_" + name
  549.             setattr(self, attr, convert_path(getattr(self, attr)))
  550.  
  551.  
  552.     def handle_extra_path (self):
  553.  
  554.         if self.extra_path is None:
  555.             self.extra_path = self.distribution.extra_path
  556.  
  557.         if self.extra_path is not None:
  558.             if type(self.extra_path) is StringType:
  559.                 self.extra_path = string.split(self.extra_path, ',')
  560.  
  561.             if len(self.extra_path) == 1:
  562.                 path_file = extra_dirs = self.extra_path[0]
  563.             elif len(self.extra_path) == 2:
  564.                 (path_file, extra_dirs) = self.extra_path
  565.             else:
  566.                 raise DistutilsOptionError, \
  567.                       ("'extra_path' option must be a list, tuple, or "
  568.                       "comma-separated string with 1 or 2 elements")
  569.  
  570.             # convert to local form in case Unix notation used (as it
  571.             # should be in setup scripts)
  572.             extra_dirs = convert_path(extra_dirs)
  573.  
  574.         else:
  575.             path_file = None
  576.             extra_dirs = ''
  577.  
  578.         # XXX should we warn if path_file and not extra_dirs? (in which
  579.         # case the path file would be harmless but pointless)
  580.         self.path_file = path_file
  581.         self.extra_dirs = extra_dirs
  582.  
  583.     # handle_extra_path ()
  584.  
  585.  
  586.     def change_roots (self, *names):
  587.         for name in names:
  588.             attr = "install_" + name
  589.             setattr(self, attr, change_root(self.root, getattr(self, attr)))
  590.  
  591.     def create_home_path(self):
  592.         """Create directories under ~
  593.         """
  594.         if not self.user:
  595.             return
  596.         home = convert_path(os.path.expanduser("~"))
  597.         for name, path in self.config_vars.iteritems():
  598.             if path.startswith(home) and not os.path.isdir(path):
  599.                 self.debug_print("os.makedirs('%s', 0700)" % path)
  600.                 os.makedirs(path, 0700)
  601.  
  602.     # -- Command execution methods -------------------------------------
  603.  
  604.     def run (self):
  605.  
  606.         # Obviously have to build before we can install
  607.         if not self.skip_build:
  608.             self.run_command('build')
  609.             # If we built for any other platform, we can't install.
  610.             build_plat = self.distribution.get_command_obj('build').plat_name
  611.             # check warn_dir - it is a clue that the 'install' is happening
  612.             # internally, and not to sys.path, so we don't check the platform
  613.             # matches what we are running.
  614.             if self.warn_dir and build_plat != get_platform():
  615.                 raise DistutilsPlatformError("Can't install when "
  616.                                              "cross-compiling")
  617.  
  618.         # Run all sub-commands (at least those that need to be run)
  619.         for cmd_name in self.get_sub_commands():
  620.             self.run_command(cmd_name)
  621.  
  622.         if self.path_file:
  623.             self.create_path_file()
  624.  
  625.         # write list of installed files, if requested.
  626.         if self.record:
  627.             outputs = self.get_outputs()
  628.             if self.root:               # strip any package prefix
  629.                 root_len = len(self.root)
  630.                 for counter in xrange(len(outputs)):
  631.                     outputs[counter] = outputs[counter][root_len:]
  632.             self.execute(write_file,
  633.                          (self.record, outputs),
  634.                          "writing list of installed files to '%s'" %
  635.                          self.record)
  636.  
  637.         sys_path = map(os.path.normpath, sys.path)
  638.         sys_path = map(os.path.normcase, sys_path)
  639.         install_lib = os.path.normcase(os.path.normpath(self.install_lib))
  640.         if (self.warn_dir and
  641.             not (self.path_file and self.install_path_file) and
  642.             install_lib not in sys_path):
  643.             log.debug(("modules installed to '%s', which is not in "
  644.                        "Python's module search path (sys.path) -- "
  645.                        "you'll have to change the search path yourself"),
  646.                        self.install_lib)
  647.  
  648.     # run ()
  649.  
  650.     def create_path_file (self):
  651.         filename = os.path.join(self.install_libbase,
  652.                                 self.path_file + ".pth")
  653.         if self.install_path_file:
  654.             self.execute(write_file,
  655.                          (filename, [self.extra_dirs]),
  656.                          "creating %s" % filename)
  657.         else:
  658.             self.warn("path file '%s' not created" % filename)
  659.  
  660.  
  661.     # -- Reporting methods ---------------------------------------------
  662.  
  663.     def get_outputs (self):
  664.         # Assemble the outputs of all the sub-commands.
  665.         outputs = []
  666.         for cmd_name in self.get_sub_commands():
  667.             cmd = self.get_finalized_command(cmd_name)
  668.             # Add the contents of cmd.get_outputs(), ensuring
  669.             # that outputs doesn't contain duplicate entries
  670.             for filename in cmd.get_outputs():
  671.                 if filename not in outputs:
  672.                     outputs.append(filename)
  673.  
  674.         if self.path_file and self.install_path_file:
  675.             outputs.append(os.path.join(self.install_libbase,
  676.                                         self.path_file + ".pth"))
  677.  
  678.         return outputs
  679.  
  680.     def get_inputs (self):
  681.         # XXX gee, this looks familiar ;-(
  682.         inputs = []
  683.         for cmd_name in self.get_sub_commands():
  684.             cmd = self.get_finalized_command(cmd_name)
  685.             inputs.extend(cmd.get_inputs())
  686.  
  687.         return inputs
  688.  
  689.  
  690.     # -- Predicates for sub-command list -------------------------------
  691.  
  692.     def has_lib (self):
  693.         """Return true if the current distribution has any Python
  694.         modules to install."""
  695.         return (self.distribution.has_pure_modules() or
  696.                 self.distribution.has_ext_modules())
  697.  
  698.     def has_headers (self):
  699.         return self.distribution.has_headers()
  700.  
  701.     def has_scripts (self):
  702.         return self.distribution.has_scripts()
  703.  
  704.     def has_data (self):
  705.         return self.distribution.has_data_files()
  706.  
  707.  
  708.     # 'sub_commands': a list of commands this command might have to run to
  709.     # get its work done.  See cmd.py for more info.
  710.     sub_commands = [('install_lib',     has_lib),
  711.                     ('install_headers', has_headers),
  712.                     ('install_scripts', has_scripts),
  713.                     ('install_data',    has_data),
  714.                     ('install_egg_info', lambda self:True),
  715.                    ]
  716.  
  717. # class install
  718.